package com.example.demo.controller;

import com.example.demo.entity.two.Department;
import com.example.demo.entity.two.MyDevicePage;
import com.example.demo.service.ConditionMonitoringDiagramService;
import com.example.demo.service.MyDevicePageService;
import com.example.demo.service.OrganizationService;
import com.example.demo.service.StaticDataService;
import com.example.demo.vo.ConditionMonitoringDiagram;
import com.example.demo.vo.GeneratorParamVO;
import com.example.demo.vo.TurbineParamVO;
import com.example.demo.vo.UnitParamVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 落羽 on 2017/8/22.
 */
@RestController
@RequestMapping("/waterplant/staticData")
public class StaticDataController {
    private static final Logger logger = LoggerFactory.getLogger(StaticDataController.class);

    // 测试用 正式的时候删除
    @Autowired
    private ConditionMonitoringDiagramService conditionMonitoringDiagramService;
//    @GetMapping("/orgniz")
//    public List<>

    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private MyDevicePageService myDevicePageService;

    @Autowired
    private StaticDataService staticDataService;

    private static final int TOP_DEPARTMENT_LEVEL = 2;

    // 测试用
    @GetMapping(value = "/demo01")
    public ConditionMonitoringDiagram conditionMonitoringDiagram() {
        ConditionMonitoringDiagram conditionMonitoringDiagram = new ConditionMonitoringDiagram();
        conditionMonitoringDiagram = conditionMonitoringDiagramService.conditionMonitoringDiagram(conditionMonitoringDiagram);
        return conditionMonitoringDiagram;
    }

    /*
       请求组织架构接口(根据等级)
     */
    @GetMapping("/department")
    @ResponseBody
    public List<Department> getOrganization(@RequestParam(value = "parentId", required = false) String parentId) {
        if (StringUtils.isEmpty(parentId)){
            return this.organizationService.getAllDepartmentByLevel(TOP_DEPARTMENT_LEVEL);
        }else {
            return this.organizationService.getDepartmentListByParentId(Integer.parseInt(parentId));
        }
    }

    /*
       请求设备台账信息(针对几个显示区域特化的接口) id为myDevicePage的Unit_Id
     */
    @GetMapping("/unit/unitParam/{id}")
    @ResponseBody
    public UnitParamVO getUParamVO(@PathVariable Integer id) {
       return staticDataService.getUnitParamVO(id);
    }

    @GetMapping("/unit/generatorParam/{id}")
    @ResponseBody
    public GeneratorParamVO getGParamVO(@PathVariable Integer id) {
        return staticDataService.getGeneratorParamVO(id);
    }

    @GetMapping("/unit/turbineParam/{id}")
    @ResponseBody
    public TurbineParamVO getTParamVO(@PathVariable Integer id) {
        return staticDataService.getTurbineParamVO(id);
    }

    @GetMapping("/device")
    @ResponseBody
    public List<MyDevicePage> getDeviceList(@RequestParam(value = "parentId") String parentId) {
        return this.myDevicePageService.findByDepartmentId(Integer.parseInt(parentId));
    }
}
